Vue.mixin({
    data: function () {
        return {
            authorizeCodeForm: {
                pageSize: 10,
                pageNumber: 1,
                totalRow: 0,
                shop_id: null
            },
            uploadAuthorizeCodeDialogVisible: false,
            generateAuthorizeCodeDialogVisible: false,
            authorizeCodeList: [],
            authorizeCodeSelection: [],
            generateAuthorizeCodeForm: {
                notes: null,
                num: null,
                expireTime: null
            },
            recentGenerateCodeList: [],
            recentGenerateCodeDialogVisible: false
        }
    },
    methods: {
        exportExcel() {
            window.open("/authorizeCode/exportExcel?condition=" + encodeURIComponent(JSON.stringify(this.authorizeCodeForm)));
        },
        uploadAuthorizeCodeSuccess(result) {
            if (result.code != 200) {
                this.$alert(result.mess, '失败', {
                    dangerouslyUseHTMLString: true
                });
            } else {
                this.$alert(result.mess, '成功', {
                    dangerouslyUseHTMLString: true
                });
            }
            this.getAuthorizeCodeData()
        },
        handleAuthorizeCodeSelectionChange(value) {
            console.log(value)
            this.authorizeCodeSelection = [];
            for (const valueElement of value) {
                this.authorizeCodeSelection.push(valueElement.id)
            }
            console.log(this.authorizeCodeSelection)
        },
        openWordList(wordList) {
            let wordListJson = JSON.parse(wordList);
            let html = "";
            for (let index in wordListJson) {
                html += wordListJson[index] + "<br>"
            }
            this.$alert(html, '词组', {
                dangerouslyUseHTMLString: true
            });
        },
        submitGenerateAuthorizeCode() {
            axios.post("/authorizeCode/generate", this.generateAuthorizeCodeForm).then(function (response) {
                if (response.data.code != 200) {
                    vm.$message.error(response.data.mess);
                } else {
                    vm.recentGenerateCodeList = response.data.data
                    vm.recentGenerateCodeDialogVisible = true
                    vm.generateAuthorizeCodeDialogVisible = false
                    vm.getAuthorizeCodeData()
                }

            });
        },
        disableAuthorizeCodeBatch() {
            axios.post("/authorizeCode/disableAuthorizeCodeBatch", {idList: this.authorizeCodeSelection}).then(function (response) {
                if (response.data.code != 200) {
                    vm.$message.error(response.data.mess);
                } else {
                    vm.$message.success("成功");
                    vm.getAuthorizeCodeData()
                }

            });
        },
        enableAuthorizeCodeBatch() {
            axios.post("/authorizeCode/enableAuthorizeCodeBatch", {idList: this.authorizeCodeSelection}).then(function (response) {
                if (response.data.code != 200) {
                    vm.$message.error(response.data.mess);
                } else {
                    vm.$message.success("成功");
                    vm.getAuthorizeCodeData()
                }

            });
        },
        uploadAuthorizeCodeError(file, fileList) {
            this.$message.error("上传失败")
        },
        beforeUploadAuthorizeCode(file) {
            var that = this;
            var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
            const extension = testmsg === 'xls'
            const extension2 = testmsg === 'xlsx'
            // const isLt2M = file.size / 1024 / 1024 < 10
            if (!extension2) {
                this.$message({
                    message: '上传文件只能是 xlsx格式!',
                    type: 'warning'
                });
                return;
            }
            console.log('正在上传')
            return extension2
        },
        changeToAuthorizeCode() {
            this.getAuthorizeCodeData();
        },
        deleteAuthorizeCodeBatch() {
            if (this.authorizeCodeSelection.length === 0) {
                this.$alert("尚未选择", '失败', {
                    dangerouslyUseHTMLString: true
                });
                return;
            }
            axios.post("/authorizeCode/deleteBatch", {idList: this.authorizeCodeSelection}).then(function (response) {
                if (response.data.code != 200) {
                    vm.$message.error(response.data.mess);
                } else {
                    vm.$message.error('删除成功');
                }
                vm.getAuthorizeCodeData()
            });
        },
        getAuthorizeCodeData() {
            axios.post("/authorizeCode/list", this.authorizeCodeForm).then(function (response) {
                if (response.data.code != 200) {
                    vm.$message.error(response.data.mess);
                } else {
                    vm.authorizeCodeForm.pageNumber = response.data.data.pageNumber;
                    vm.authorizeCodeForm.totalRow = response.data.data.totalRow;
                    vm.authorizeCodeList = response.data.data.list;
                }
                vm.authorizeCodeSelection = []
            });
        }
    },
    watch: {},
    mounted: function () {
    }
})
